<template>
	<view class="pages">
		<view class="search_warp u-flex-x-center">
			<view class="u-flex-xy-center">
				<text class="name">用户名</text>
				<view class="user_id">
					<input type="number" v-model="num_id"  placeholder="请输入ID"/>
				</view>
				<view class="user_id">
					<input type="number" v-model="object_id" placeholder="请输入ID"/>
				</view>
				<view class="search" @click="search">
					<text>搜索</text>
				</view>
			</view>
		</view>
		<view class="main">
			<view v-if="is_daxian==false">
				<image
					src="https://hl-1316403513.cos.ap-shanghai.myqcloud.com/static/%E9%BB%98%E8%AE%A4%E5%8D%A1%E7%89%87%E4%B8%80.png"
					mode="widthFix" style="margin-bottom:20rpx;"></image>
				<image
					src="https://hl-1316403513.cos.ap-shanghai.myqcloud.com/static/%E9%BB%98%E8%AE%A4%E5%8D%A1%E7%89%87%E4%B8%80.png"
					mode="widthFix"></image>
			</view>
			<view class="item u-flex-between u-flex" v-for="(item,index) in proData" :key="index"
				@click="skip_details(item)" v-else>
				<view class="avatar">
					<u--image :src="get_src(item.matchmakerMeitu)" height="232" width="184">
					</u--image>
				</view>
				<view class="u-flex-1">
					<view class="u-flex u-flex-between item_top">
						<view class="u-flex-y-center">
							<text>{{item.userId}}</text>
							<view class="sex">
								<image :src="`${$http_cos}${item.sex=='男'?'/static/boy':'/static/%E5%A5%B3'}.png`"
									mode="heightFix"></image>
							</view>
						</view>
						<text class="descriptiveDescription">{{item.descriptiveDescription}}</text>
					</view>
					<view class="info_introduce">
						<text>
							{{item.title}}
						</text>
					</view>
				</view>
			</view>
		</view>
		<view class="footer">
			<view class="btn" :class="is_daxian?'orage':'gray'" @click="star_qx">
				<text>开始牵线</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getSinglesSquare,
		getUserInfo,
		getIdsUserList,
		arrangeAMeeting
	} from '@/common/api.js'
	const app = getApp();
	export default {
		data() {
			return {
				is_daxian: false,
				$http_cos: app.$http_cos,
				proData: [],
				num_id: '',
				isRefresh: true,
				user_id: '',
				object_id: '',
				formData: {
					id: '',
					u_id: ''
				}
			}
		},
		onLoad() {

		},
		watch: {
			num_id(val) {
				this.formData.id = Number(val)
			},
			object_id(val) {
				this.formData.u_id = Number(val)
			}
		},
		onShow() {
			// alert('1')

			this.get_SinglesSquare()
			setTimeout(() => {
				this.isRefresh = true
			}, 700)
		},
		onReachBottom() {
			// alert('下啦')
			if (this.isRefresh == false) return
			this.get_SinglesSquare()

		},
		onPullDownRefresh() {
			// setTimeout(()=>{
			// 				this.onSearch()
			// 				uni.stopPullDownRefresh();//关闭刷新状态
			// 			},2000);	
		},
		methods: {
			search(){
				if(this.num_id==''||this.object_id==''){
					uni.$u.toast('ID不能为空')
					return
				}
				let data={
					params: {
						userId:this.formData.u_id+','+this.formData.id
					}
				}	
				getIdsUserList(data,{
					custom: {
						auth: false,
						toast: false,
						catch: false
					}
				}).then((result) => {
					this.is_daxian=true
					console.log(result)
					this.proData=result
					
					// this.user_info = r
				}).catch((err) => {
					
				})
			},
			init(){
				this.num_id=''
				this.object_id=''
				this.is_daxian=false
			},
			star_qx() {
				if (this.is_daxian == false) {
					return
				}
				let data={
					userId:this.formData.u_id+','+this.formData.id
				}	
				arrangeAMeeting(data,{
					custom: {
						auth: false,
						toast: false,
						catch: false
					}
				}).then((result) => {
					uni.$u.toast('牵线成功')
					this.init()
				}).catch((err) => {
					
				})
			},
			
			get_UserInfo() {
				return new Promise(resolve => {
					
					getUserInfo({
						custom: {
							auth: false,
							toast: false,
							catch: false
						}
					}).then((result) => {
						resolve(result)
						// this.user_info = r
					}).catch((err) => {
						reject(err)
					})
				})
			},
			skip_details(item) {
				uni.navigateTo({
					url: '/pagesA/square_details/index' + '?id=' + item.userId
				})
			},
			get_src(it) {
				let {
					url
				} = JSON.parse(it)[0]
				return url + '?imageView2/2/w/750/h/q/85'
			},
			async skip(url) {
				try {
					if (uni.getStorageSync('access_token')) {
						let user_info = await this.get_UserInfo()
						if (user_info.memberId > 0 || user_info.isMatchmaker === 1) {
							uni.navigateTo({
								url: url + '?formData=' + JSON.stringify(this.formData)
							})
						} else {
							uni.$u.toast('请“我的-联系红娘”成为线下门店会员才能使用此功能！')
						}
					} else {
						uni.navigateTo({
							url: '/pages/guide/index'
						})
					}
				} catch (e) {
					//TODO handle the exception
				}

			},
			get_SinglesSquare() {
				let data = {
					params: this.formData
				}
				getSinglesSquare(data, {
					custom: {
						auth: false,
						toast: false,
						catch: false
					}
				}).then((result) => {
					// this.proData = [...this.proData, ...result.list]
					// this.formData.count=result.count
					// result.list.length <= 0 ? this.status = 'noMore' : this.status = 'more'
					// this.formData.page++;
				}).catch((err) => {

				})

			}
		}
	}
</script>

<style lang="scss">
	.pages {
		height: 100vh;
		overflow: hidden;

		// padding-bottom: env(safe-area-inset-bottom);
		/deep/ .z-paging-content {
			margin-top: 96rpx;
		}

		.search_warp {
			padding: 12rpx 24rpx;
			box-sizing: border-box;
			background-color: #fff;
			height: 136rpx;
			position: fixed;
			left: 0;
			top: 0;
			right: 0;
			z-index: 2222;

			.name {
				font-size: 28rpx;
				color: #111111;
				margin-right: 23rpx;
			}

			.user_id {
				width: 188rpx;
				height: 72rpx;
				background-color: #fff;
				border-radius: 10rpx;
				border: 2rpx solid #C2C2C2;
				margin-right: 20rpx;

				input {
					height: 100%;
					padding-left: 20rpx;
				}
			}

			.search {
				width: 170rpx;
				background-color: #FF6617;
				color: #fff;
				text-align: center;
				line-height: 72rpx;
				height: 72rpx;
				border-radius: 10rpx;
			}
		}

		.main {
			padding: 20rpx 24rpx;
			box-sizing: border-box;
			margin-top: 136rpx;

			.item {
				&:last-child {
					margin-bottom: 0rpx;
				}

				padding:24rpx 20rpx;
				background-color: #fff;
				border-radius:10rpx;
				margin-bottom:24rpx;

				.avatar {
					width: 184rpx;
					height: 232rpx;
					border-radius: 10rpx;
					overflow: hidden;
					margin-right: 24rpx;
					// /deep/.u-image{
					// 	width: 100% !important;
					// 	height:100% !important;
					// }
					// background-color:red;
				}

				.item_top {
					padding: 9rpx 5rpx 9rpx 0;
					box-sizing: border-box;
					align-items: center;

					.descriptiveDescription {
						width: 270rpx;
						font-size: 28rpx;
						font-weight: 400;
						text-align: right;
						color: #111111;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 1;
						letter-spacing: 30;

					}

					text {
						font-weight: 400;

						&:first-child {
							font-size: 34rpx;
							;
							color: #000000;
						}

						&:last-child {
							color: #FF7612;
							font-size: 28rpx;
						}
					}

					.sex {
						width: auto;
						height: 28rpx;
						margin-left: 8rpx;
					}
				}

				.info_introduce {
					text {
						line-height: 42rpx;
						font-size: 28rpx;
						font-weight: 400;
						color: #111111;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 4;
						letter-spacing: 30;
					}
				}

			}
		}

		.footer {
			height: 115rpx;
			position: fixed;
			padding: 19rpx 32rpx;
			box-sizing: border-box;
			bottom: 0;
			left: 0;
			right: 0;
			background-color: #fff;

			.btn {
				width: 100%;
				height: 100%;
				border-radius: 39px;
				color: #fff;
				display: flex;
				align-items: center;
				justify-content: center;
				&.gray {
					background-color: #B5B5B5;
				}

				&.orage {
					background-color: #FF6617;
				}
			}
		}
	}
</style>